package com.smartwasser.yunhtgl.apphtgl.utils;

import android.content.Context;
import android.content.SharedPreferences;

public class SharedUtils {
    private final static String CONFIG = "config";
    private static SharedPreferences sp;

    public static boolean getBooleanData(Context context, String key, boolean defulat) {
        if (sp == null) {
            sp = context.getSharedPreferences(CONFIG, Context.MODE_PRIVATE);
        }
        boolean nu = sp.getBoolean(key, defulat);
        return nu;
    }

    public static void setBooleanDate(Context context, String key, boolean jilu) {
        if (sp == null) {
            sp = context.getSharedPreferences(CONFIG, Context.MODE_PRIVATE);
        }
        SharedPreferences.Editor ed = sp.edit();
        Logger.i("Boolean");
        Logger.i("key = " + key + "  value = " + jilu);
        if (!(getBooleanData(context, key, false) == jilu)) {
            Logger.i("2次数据不一样，储存");
            ed.putBoolean(key, jilu);
            ed.commit();
        } else {
            Logger.i("2次数据一样，不储存");
        }
        Logger.i("_____________________________________");
    }

    public static String getStringData(Context context, String key, String defulat) {
        if (sp == null) {
            sp = context.getSharedPreferences(CONFIG, Context.MODE_PRIVATE);
        }
        String str = sp.getString(key, defulat);
        return str;
    }

    public static void setStringData(Context context, String key, String nihao) {
        if (sp == null) {
            sp = context.getSharedPreferences(CONFIG, Context.MODE_PRIVATE);
        }
        SharedPreferences.Editor ed = sp.edit();
        Logger.i("String");
        Logger.i("key = " + key + "  value = " + nihao);
        if (!(getStringData(context, key, "").equals(nihao))) {
            Logger.i("2次数据不一样，储存");
            ed.putString(key, nihao);
            ed.commit();
        } else {
            Logger.i("2次数据一样，不储存");
        }
        Logger.i("_____________________________________");
    }
}
